﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlackJack1
{
    internal class Pocker
    {
        
        public List<Card> pockers = new List<Card>();
        private Random rng = new Random();
        

        public Pocker()
        {
            pockers = new List<Card>();
            string[] colors = { "黑桃", "红桃", "梅花", "方片" };
            int[] nums = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 };
            //这里牌的数量是52张
            foreach (string color in colors)
            {
                foreach (int num in nums)
                {
                    pockers.Add(new Card(color, num));
                }
            }
            //for (int i = 0; i < 4; ++i)
            //{
            //    for (int j = 1; j <= 13; ++j)
            //    {
            //        pockers[(i * 13) + j - 1] = new Card();
            //        switch (i)
            //        {
            //            case 0:
            //                pockers[(i * 13) + j - 1].Color = "黑桃";
            //                break;
            //            case 1:
            //                pockers[(i * 13) + j - 1].Color = "红桃";
            //                break;
            //            case 2:
            //                pockers[(i * 13) + j - 1].Color = "梅花";
            //                break;
            //            case 3:
            //                pockers[(i * 13) + j - 1].Color = "方片";
            //                break;
            //        }
            //        pockers[(i * 13) + j - 1].Num = j;
            //    }
            //}
        }
        public void Shuffle()
        {
            int n = pockers.Count();
            while (n > 1)
            {
                int k = rng.Next(n--);
                Card value = pockers[n];
                pockers[n] = pockers[k];
                pockers[k] = value;
            }
        }

        public Card Draw()
        {
            if(pockers.Count > 0)
            {
                Card drawPocker = pockers[pockers.Count - 1];
                pockers.RemoveAt(pockers.Count - 1);
                return drawPocker;
            }
            else
            {
                //如果牌组为空，则直接返回null
                return null;
            }
        }
    }
    
}

